package malus.shaofeng.com.beiwomusic.activity;

import android.app.Activity;
import android.app.Dialog;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebView;
import android.widget.Toast;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

import malus.shaofeng.com.beiwomusic.R;
import malus.shaofeng.com.beiwomusic.utils.Constants;
import malus.shaofeng.com.beiwomusic.view.SildingFinishLayout;
import malus.shaofeng.com.beiwomusic.view.Topbar;

@ContentView(R.layout.activity_setting_disclarmer)
public class SettingDisclarmerActivity extends Activity implements SildingFinishLayout.OnSildingFinishListener, Topbar.onTopbarClickListener {
    @ViewInject(R.id.settingDisclarmerLayout)
    SildingFinishLayout settingDisclarmerLayout;
    @ViewInject(R.id.topbar)
    Topbar topbar;
    @ViewInject(R.id.space_setting_disclaimer_webview)
    WebView disclaimerWebView;
    Dialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        ViewUtils.inject(this);
        settingDisclarmerLayout.setOnSildingFinishListener(this);
        topbar.setOnTopbarClickListener(this);
        HttpUtils httpUtils=new HttpUtils();
        //进度条
        dialog = new Dialog(this);
        dialog.setContentView(R.layout.item_running);
        dialog.getWindow().setBackgroundDrawableResource(R.drawable.transaction);
        dialog.setCancelable(false);
        dialog.show();
        httpUtils.send(
                HttpRequest.HttpMethod.GET,
                "http://kaixinai.com/qms/disclaimer.html",
                new RequestCallBack<Object>() {
            @Override
            public void onSuccess(ResponseInfo<Object> objectResponseInfo) {
                disclaimerWebView.loadDataWithBaseURL(
                        Constants.URL.IMAGE_URL,
                        objectResponseInfo.result.toString(),
                        "text/html","utf-8",null);
                dialog.cancel();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                dialog.cancel();
                Toast.makeText(SettingDisclarmerActivity.this,"加载错误了>.<~",Toast.LENGTH_SHORT);
            }
        });
    }


    @Override
    public void onSildingFinish() {

        finish();
        overridePendingTransition(0,R.anim.trans_slider_out);
    }

    @Override
    public void onLeftButtonClick() {

        finish();
        overridePendingTransition(0,R.anim.trans_slider_out);
    }

    @Override
    public void onRightButtonClick() {

    }

    @Override
    public void onSearchButtonClick() {

    }

    @Override
    public void onBackPressed() {
        finish();
        overridePendingTransition(0,R.anim.trans_slider_out);
    }
}
